package com.redstars.tool.screw.controller;

import cn.smallbun.screw.core.engine.EngineFileType;
import com.redstars.tool.screw.service.ScrewService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : zhouhx
 * 数据库文档
 * @date : 2023/3/31 10:08
 */
@RestController
@RequestMapping("/screw/db-doc")
public class ScrewController {
    @Resource
    ScrewService screwService;
    /**
     *
     * @author zhuohx
     * @description 导出 html 格式的数据文档
     * @parms  [deleteFile 是否删除在服务器本地生成的数据库文档, datasourceId 数据源id,response]
     * @return void
     * @throws
     * @date 2023/3/31 10:47
     */
    @GetMapping("export-html")
    public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile,
                           @RequestParam("datasourceId")String datasourceId,
                           HttpServletResponse response) throws IOException {
        screwService.doExprotFile(datasourceId,EngineFileType.HTML, deleteFile, response);
    }

    /**
     *
     * @author zhuohx
     * @description 导出 word 格式的数据文档
     * @parms  [deleteFile 是否删除在服务器本地生成的数据库文档, datasourceId 数据源id, response]
     * @return void
     * @throws
     * @date 2023/3/31 10:48
     */
    @GetMapping("export-word")
    public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile,
                           @RequestParam("datasourceId")String datasourceId,
                           HttpServletResponse response) throws IOException {
        screwService. doExprotFile(datasourceId,EngineFileType.WORD, deleteFile, response);
    }

    /**
     *
     * @author zhuohx
     * @description 导出 markdown 格式的数据文档
     * @parms  [deleteFile 是否删除在服务器本地生成的数据库文档, datasourceId 数据源id, response]
     * @return void
     * @throws
     * @date 2023/3/31 10:48
     */
    @GetMapping("export-markdown")
    public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile,
                               @RequestParam("datasourceId")String datasourceId,
                               HttpServletResponse response) throws IOException {
        screwService.doExprotFile(datasourceId,EngineFileType.MD, deleteFile, response);
    }
}
